﻿//-----------------------------------------------------------------------
// <copyright file="IRepository.cs" company="FastNET Services">
//     Copyright (c) 2008-2013. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using System.Collections.Generic;

#endregion

namespace FastNet.RepositorySystem.Interfaces
{
    /// <summary>
    /// Base interface for all IData based repositories
    /// </summary>
    public interface IRepository
    {
        /// <summary>
        /// Deletes all data from this repository.
        /// </summary>
        void Delete();

        /// <summary>
        /// Deletes all data from this repository.
        /// </summary>
        /// <param name="permanently">Boolean whether or not to permanently remove the data or to just mark it for cleanup later</param>
        void Delete(bool permanently);
    }

    /// <summary>
    /// Base interface for all repositories
    /// </summary>
    /// <typeparam name="T">IData the repository represents</typeparam>
    public interface IRepository<T>
        : IRepository
        where T : IData
    {
        /// <summary>
        /// Retrieves all instances of <typeparamref name="T"/> from the repository
        /// </summary>
        /// <returns>IEnumerable of the requested <typeparamref name="T"/></returns>
        IList<T> Retrieve();

        /// <summary>
        /// Retrieves all instances of <typeparamref name="T"/> from the repository
        /// </summary>
        /// <param name="includeDeleted">Boolean whether or not to include deleted entries</param>
        /// <returns>IEnumerable of the requested <typeparamref name="T"/></returns>
        IList<T> Retrieve(bool includeDeleted);

        /// <summary>
        /// Deletes the requested <typeparamref name="T"/>
        /// </summary>
        /// <param name="data">A <typeparamref name="T"/> to delete from the repository</param>
        /// <exception cref="ArgumentNullException">Thrown if data is null</exception>
        /// <exception cref="InvalidCastException">Thrown if the data is of the wrong type for this data source</exception>
        /// <exception cref="InvalidOperationException">Thrown if the <typeparamref name="T"/> is new or already deleted</exception>
        void Delete(T data);

        /// <summary>
        /// Deletes the requested <typeparamref name="T"/>
        /// </summary>
        /// <param name="data">A <typeparamref name="T"/> to delete from the repository</param>
        /// <param name="permanently">Boolean whether or not to permanently remove the data or to just mark it for cleanup later</param>
        /// <exception cref="ArgumentNullException">Thrown if data is null</exception>
        /// <exception cref="InvalidCastException">Thrown if the data is of the wrong type for this data source</exception>
        /// <exception cref="InvalidOperationException">Thrown if the <typeparamref name="T"/> is new or already deleted</exception>
        void Delete(T data, bool permanently);

        /// <summary>
        /// Saves the requested <typeparamref name="T"/>
        /// </summary>
        /// <param name="data">A <typeparamref name="T"/> to save to the repository</param>
        /// <exception cref="ArgumentNullException">Thrown if data is null</exception>
        /// <exception cref="InvalidCastException">Thrown if the data is of the wrong type for this data source</exception>
        void Save(T data);

        /// <summary>
        /// Creates a new instance of <typeparamref name="T"/>
        /// </summary>
        /// <returns>New Instance of <typeparamref name="T"/></returns>
        T Create();
    }
}